<!-- 预答辩申请审批 -->
<template>
  <div class="edu-page-warp">
    <el-card shadow="never">
      <el-row type="flex" justify="space-between" class="con_title">
        <el-col :span="6">
          <h2 class="edu-page-title">{{currentType ===
            'viewDetail'?$t('preDefense.preDefenseView'):$t('preDefense.preDefenseAuditTitle')}}</h2>
        </el-col>
        <el-col :span="3" style="text-align: right;">
          <el-button v-if="!idTip" @click="back">{{$t('message.return')}}</el-button>
        </el-col>
      </el-row>
      <inputOption ref="inputOption" :row="row" :options="options" :footerFlag="false"
                   :detailsFlag="currentType==='viewDetail'" :editFlag="true" @emit:complete="complete"
                   :rollInfo="rollInfo" :fromCheckDetail="fromCheckDetail" :idTip="idTip"></inputOption>
    </el-card>
    <el-card shadow="never">
      <auditProgressInfo :data="auditList"></auditProgressInfo>
    </el-card>
  </div>
</template>

<script>
  import baseData from '../common/baseData';
  import auditProgressInfo from '../common/auditProgressInfo';
  import inputOption from 'common/src/views/preDefense/preDefenseApply/inputOption';
  import {approvalThrough, approvalReject, approvelDetail} from "common/src/api/approval";

  export default {
    components: {
      baseData,
      inputOption,
      auditProgressInfo
    },
    mixins: [],
    props: {
      row: {
        type: Object,
        default: {}
      },
      currentType: {
        type: String,
        default: ""
      },
      options: {
        type: Object,
        default: {}
      },
      rollInfo:{
        type: Object,
        default: {}
      },
      fromCheckDetail:{
        type: Boolean,
        required: false
      },
      idTip:{
        type: String,
        default:""
      }
    },
    data() {
      return {
        label: [
          {label: this.$t('label.stuCode'), prop: 'stuNo'},
          {label: this.$t('label.stuName'), prop: 'stuName'},
          {label: this.$t('label.college'), prop: 'academyName'},
          {label: this.$t('label.major'), prop: 'majorName'},
          {label: this.$t('label.grade'), prop: 'grade'},
          {label: this.$t('label.trainingLevel'), prop: 'eduLevelI18n'},
          {label: this.$t('label.trainingCategory'), prop: 'eduModeI18n'},
          {label: this.$t('achievementApply.teacherName'), prop: 'stuTutorName'}
        ],
        auditList: [],
      };
    },
    computed: {},
    created() {

    },
    mounted() {
      if(this.rollInfo&&this.rollInfo.no){
        this.row.workFlowId=this.rollInfo.no;
      }
      this.getApprovelDetail();
    },
    methods: {
      back() {
        this.$emit('emit:back');
      },
      complete(type, msg) {
        let audits = this.$refs.inputOption.audits;
        if(!this.row.workFlowId || this.row.workFlowId === ''){
          this.$message.error(this.$t('achievementApply.reapplyTips'));
            return;
        }
        if (audits.staus === 'unpass') {
          this.ApplyReject(audits);
        } else if (audits.staus === 'pass') {
          this.ApplyPass(audits)
        }
      },
      // 审批通过
      ApplyPass(audits) {
        this.$eduConfirm(this.$t('teachers.comfirmApprove'), this.$t('common.btn.approve')).then(() => {
          if (audits.msg && audits.msg.includes('$')) {
            this.$message.error(this.$t('achievementApply.specilTips'));
            return;
          }
          let param = {
            no: this.row.workFlowId,
            content: audits.msg && audits.msg !== '' ? audits.msg : '同意',
            approveAttachment: [],
            oaNo: this.row.workFlowId,
            remark: null,
            callbackEachTime: true
          };
          approvalThrough(param).then(res => {
            if (res.code == 200) {
              if(this.rollInfo&&this.rollInfo.no){
                this.fromCheckDetail=true;
                //this.$router.go(-1);
              }else{
                this.back();
              }
              this.$message({
                type: "success",
                message: this.$t('shortTermApprove.examinePass')
              });
            }
          });
        });
      },
      // 审批驳回
      ApplyReject(audits) {
        this.$confirm(this.$t('achievementApply.refuseInfo'), this.$t('achievementApply.tipsTitle'), {
          confirmButtonText: this.$t('message.confirm'),
          cancelButtonText: this.$t('message.cancel'),
          type: 'warning'
        }).then(() => {
          if (!audits.msg || audits.msg === '') {
            this.$message.error(this.$t('achievementApply.refuseRuleTips'));
            return;
          }
          if (audits.msg.includes('$')) {
            this.$message.error(this.$t('achievementApply.specilTips'));
            return;
          }
          let param = {
            content: audits.msg,
            no: this.row.workFlowId,
            approveAttachment: [],
            oaNo: this.row.workFlowId,
            remark: null,
            callbackEachTime: true
          };
          approvalReject(param).then(res => {
            if (res.code == 200) {
              if(this.rollInfo&&this.rollInfo.no){
                this.fromCheckDetail=true;
                //this.$router.go(-1);
              }else{
                this.back();
              }
              this.$message({
                type: "success",
                message: this.$t('shortTermApprove.examinePass')
              });
            }
          });
        });
      },
      // 获取审批记录
      getApprovelDetail() {
        if (!this.row.workFlowId || this.row.workFlowId === '') {
          if(this.rollInfo.listApproveHistory){
            this.auditList=this.rollInfo.listApproveHistory;
          }
          return;
        }
        let param = {
          no: this.row.workFlowId
        };
        approvelDetail(param).then(res => {
          if (res && res.data) {
            this.auditList = res.data.listApproveHistory;
          }
        });
      },
    }
  };
</script>

<style scoped lang="scss">
  .con {
    background-color: white;
    padding: 20px;

    &_title {
      width: 100%;
      border-bottom: solid #ccc 2px;
      padding-bottom: 20px;
    }

    &_footer {
      display: flex;
      flex-direction: row-reverse;
      border-top: solid #ccc 1px;
      padding-top: 10px;
    }
  }
</style>
